package com.yusong.algorithm.array;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class ReverseNumber9 {


    public static void main(String[] args) {
        int[] grid = {0,0,1};

        ReverseNumber9 main = new ReverseNumber9();

        main.isPalindrome(12321);

        String v1 = "0.1";
        String v2 = "1.1";

        main.compareVersion(v1, v2);
    }


    public boolean isPalindrome(int x) {
        //边界判断
        if (x < 0) return false;
        int div = 1;
        //
        while (x / div >= 10) div *= 10;
        while (x > 0) {
            int left = x / div;
            int right = x % 10;
            if (left != right) return false;
            x = (x % div) / 10;
            div /= 100;
        }
        return true;
    }

    public int compareVersion(String version1, String version2) {
        String[] s1= version1.split("\\.");
        String[] s2= version2.split("\\.");
        int index = 0;
        int length1 = s1.length;
        int length2 = s2.length;
        int length = Math.min(length1, length2);
        while(index < length){
            int num1 = Integer.parseInt(s1[index]);
            int num2 = Integer.parseInt(s2[index]);
            if(num1 > num2){
                return 1;
            }
            if(num1 < num2){
                return -1;
            }
            index++;
        }
        if(length1 > length2){
            return 1;
        }else if(length1 < length2){
            return -1;
        }


        return 0;
    }
}
